Create New Module

This guide outlines how to add a new module to the project using baselines convention plugins.

1. Choose the Layer

Determine where your module belongs to maintain architectural separation:

LayerPurpose
uiFeature screens, navigation, theming.
domainBusiness logic, use-case orchestration, rules.
dataRepository implementations, network, database.
toolkitReusable utilities, DI, logging, crypto, etc.

Action: Create a directory under the chosen layer (e.g., ui/profile).


2. Configure the Module

Choose the type of module you are building below.

Note: For both options, register the new module in settings.gradle.kts, e.g. include(":ui:profile").

Namespaces are derived from BuildConfig.NAMESPACE in build-logic/convention/src/main/kotlin/io/baselines/gradle/BuildConfig.kt and the module path. For example, a generated namespace of com.example.myapp and :ui:profile produce com.example.myapp.ui.profile. Path segments are lowercased and hyphens are removed, so :ui:design-system uses the suffix .ui.designsystem.

For shared modules with DI contributions, also add the module to commonMain.dependencies in app/multiplatform/build.gradle.kts. Apply alias(libs.plugins.baselines.di) in modules that use Metro.

For modules with unit tests, add alias(libs.plugins.baselines.testing.unit) to the plugins block. It configures test dependencies and Android unit/host tests for either module type.

🅰️ Option A: Multiplatform Module (Android + iOS)

Standard choice for most logic and UI.

1. Create build.gradle.kts Create the file inside your new directory and paste the following content.

kotlin
1plugins {
2 alias(libs.plugins.baselines.multiplatform.library)
3 // Only needed if this module contains UI/Compose code
4 alias(libs.plugins.baselines.compose)
5}
6
7// Define dependencies
8kotlin {
9 sourceSets {
10 commonMain.dependencies {
11 // Shared dependencies
12 }
13 androidMain.dependencies {
14 // Android specific
15 }
16 iosMain.dependencies {
17 // iOS specific
18 }
19 }
20}

2. Create Folder Structure Create the source folders matching your generated namespace. <namespace-path> replaces dots with directory separators; for example, com.example.myapp becomes com/example/myapp:

text
1📂 src
2 ┣ 📂 commonMain/kotlin/<namespace-path>/ui/profile
3 ┣ 📂 androidMain/kotlin/<namespace-path>/ui/profile
4 ┗ 📂 iosMain/kotlin/<namespace-path>/ui/profile

🅱️ Option B: Android-Only Module

Use for platform-specific features (e.g., Google Services, Camera, Splash).

1. Create build.gradle.kts Create the file inside your new directory and paste the following content.

kotlin
1plugins {
2 alias(libs.plugins.baselines.android.library)
3 // Only needed if this module contains UI/Compose code
4 alias(libs.plugins.baselines.compose)
5}
6
7// Define dependencies
8dependencies {
9 // Android dependencies
10}

2. Create Folder Structure Create the standard Android source folder matching your namespace:

text
1📂 src
2 ┗ 📂 main/kotlin/<namespace-path>/ui/profile

Compose Resources

The Compose convention plugin configures src/commonMain/composeResources and generates a module-local Res class in the derived namespace. It also reads compose-stability.conf from the project root. Keep stability declarations consistent with the actual types.